import java.util.Scanner;

/** 
   A program reads two integer values
   and prints out the larger of the two.
   If the values are equal, only one of the value is printed.
*/
public class LexiOrder
{
   public static void main(String[] args)
   {
      // Print prompt to enter two words (strings)
      System.out.println("Please enter two words: ");

      // Read in both integer values
      Scanner in = new Scanner(System.in);
      String word1 = in.next();
      String word2 = in.next();

      // Determine the correct alphabetical order of words
      // and print out the words in one line, in order.

      // Your work here
      int flag = 0;
      int i = 0, j = 0;
      while (i<word1.length() || j<word2.length())
      {
         if (i>=word1.length() && j < word2.length()) {
            System.out.println(word1 + " " + word2);
            flag = 1;
            break;
         }
         else if (i < word1.length() && j >= word2.length()) {
            System.out.println(word2 + " " + word1);
            flag = 1;
            break;
         }
         if (word1.charAt(i) < word2.charAt(j)) {
            System.out.println(word1 + " " + word2);
            flag = 1;
            break;
         }
         else if (word1.charAt(i) > word2.charAt(j)) {
            System.out.println(word2 + " " + word1);
            flag = 1;
            break;
         }
         i ++;
         j ++;
      }
      if (flag == 0) System.out.println(word1);
   }
}